export const USER_INFO_KEY = 'userinfo' // 用户信息
export const USER_NAME = 'username' // 用户信息
export const SETION_ID = 'sesionid' // sesionid
export const DOMAIN_ID = 'domainId' // domainId
export const RES_CODE = 'resCode'
export const DOMAIN_NANE = 'domainName'
export const FORM_FLAG = 'formFlag'

// home页获取用户信息
export const newGetDomainId = () => {
  const domainId = JSON.parse(localStorage.getItem(DOMAIN_ID))
  if (domainId) {
    return domainId
  } else {
    return false
  }
}
// home页获取用户信息
export const getUserinfo = () => {
  const userinfo = JSON.parse(localStorage.getItem(USER_INFO_KEY))
  if (userinfo) {
    return userinfo
  } else {
    return false
  }
}
// home页获取用户信息
export const getDomainId = () => {
  const userinfo = JSON.parse(localStorage.getItem(USER_INFO_KEY))
  if (userinfo) {
    return userinfo.domainId
  } else {
    return false
  }
}
// home页获取用户信息
export const getDomainName = () => {
  const userinfo = JSON.parse(localStorage.getItem(USER_INFO_KEY))
  if (userinfo) {
    return userinfo.domainName
  } else {
    return false
  }
}
export const setDomainId = (domainId) => {
  let userinfo = JSON.parse(localStorage.getItem(USER_INFO_KEY))
  if (userinfo) {
    userinfo.domainId = domainId
    localStorage.setItem(USER_INFO_KEY, JSON.stringify(userinfo))
  }
}
export const setDomainName = (domainName) => {
  let userinfo = JSON.parse(localStorage.getItem(USER_INFO_KEY))
  if (userinfo) {
    userinfo.domainName = domainName
    localStorage.setItem(USER_INFO_KEY, JSON.stringify(userinfo))
  }
}
// home页获取用户信息
export const getResCode = () => {
  return localStorage.getItem('resCode')
}
export const setResCode = (rescode) => {
  localStorage.setItem('resCode', rescode)
}

// home页获取获取sesionid并过滤
export const getSesionid = () => {
  const sessionId = localStorage.getItem(SETION_ID)
  if (sessionId) {
    return sessionId
  } else {
    return false
  }
}

// function getCookie(cookieName) {
//   let strCookie = document.cookie
//   let arrCookie = strCookie.split('; ')
//   for (let i = 0; i < arrCookie.length; i++) {
//     let arr = arrCookie[i].split('=')
//     if (cookieName === arr[0]) {
//       return arr[1]
//     }
//   }
//   return ''
// }
